package org.mzy.basic.controller;

import org.mzy.basic.dto.AccountLoginDto;
import org.mzy.basic.dto.AccountLoginDto2;
import org.mzy.basic.dto.WechatLoginDto;
import org.mzy.basic.service.ILoginService;
import org.mzy.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

/**
 * @Package: org.mzy.basic.controller
 * @ClassName: loginController
 * @Date:2022/10/21 14:50
 * @Description:
 */
@RestController
@RequestMapping("/login")
public class loginController {
    @Autowired
    private ILoginService loginService;

    /**
     * 账号登陆
     *
     * @param dto
     * @return
     */
    @PostMapping("/account")
    public AjaxResult account(@RequestBody @Valid AccountLoginDto dto) {
        // 将参数存入map
        Map<String, Object> map = loginService.accountLogin(dto);
        return AjaxResult.me().success(map);
    }

    @PostMapping("/phoneCode")
    public AjaxResult phonnCode(@RequestBody @Valid AccountLoginDto2 dto) {
        // 将参数存入map
        Map<String, Object> map = loginService.phonnCodeLogin(dto);
        return AjaxResult.me().success(map);
    }

    /**
     * 微信登陆
     *
     * @param dto
     * @return
     */
    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody WechatLoginDto wechatLoginDto) {
        return loginService.wechatLogin(wechatLoginDto);
    }

    /**
     * 微信登陆绑定
     *
     * @param dto
     * @return
     */
    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody WechatLoginDto dto) {
        Map<String, Object> stringObjectMap = loginService.wechatBinder(dto);
        return AjaxResult.me().success(stringObjectMap);
    }
}
